<template>
    <h2 algin="center">管理员增加借款</h2>
    <table class="table table-bordered">
        <tr>
            <td>借款款项名称</td>
            <td>
                <input type="text" v-model="state.B_Name" />
            </td>
        </tr>
        <tr>
            <td>借款最高金额</td>
            <td><input type="text" v-model="state.B_Money" /></td>
        </tr>
        <tr>
            <td>借款最高年限</td>
            <td><input type="text" v-model="state.B_Year" /></td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                      <select v-model="state.I_Id">
                        <option value="0">--请选择--</option>
                        <option :value="item.I_Id" v-for="item in list">{{ item.I_Year}}年{{item.I_Interest}}%</option>
                      </select>
                    </td>
        </tr>
        <tr>
            <td>借款款项简介</td>
            <td><input type="textarea" v-model="state.B_Info" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="修改" @click="upd" />
                <input type="hidden" v-model="state.B_Id" /></td>
        </tr>
        
    </table>
    </template>
    
    <script setup lang="ts">
    import{reactive,ref,toRefs,onMounted} from 'vue'
    import { useRouter,useRoute } from 'vue-router'
    import axios from 'axios'
    let route=useRoute()
    let router=useRouter()
    let data:any=reactive({
        list:[],
        state:{
            B_Name:'',
            B_Year:'',
            B_Money:'',
            I_Id:'0',
            B_Info:'',
            B_Id:route.query.id
        }
    })
    let {state,list}=toRefs(data)
    
    const upd=()=>{
        axios({
            url:"/api/Borrow/PostBorrowUpd",
            method:'post',
            data:state.value
        })
        .then(res=>{
            console.log(res.data.data);
            if(res.data.data>0){
                alert("修改成功");
                router.push("/main/borrowList")
            }
            else{
                alert("修改失败");
            }
        })
        .catch(err=>{
            console.log(err);
        })
       
    }
    onMounted(()=>{
        seltype();
        fan();
    })
    const seltype=()=>{
        axios({
            url:"/api/Borrow/SelInterest",
            method:'get',
            
        })
        .then(res=>{
            console.log(res.data.data);
            list.value=res.data.data;
        })
        .catch(err=>{
            console.log(err);   
        })
    }
    const fan=()=>{
        axios({
            url:"/api/Borrow/GetBorrowMoneyList",
            method:'get',
            params:{id:route.query.id},
        })
        .then(res=>{
            console.log(res.data.data);
            state.value=res.data.data[0];
        })
        .catch(err=>{
            console.log(err);   
        })
    }
    
    
    
    </script>
    
    
    
    <style scoped>
    
    </style>